<?
require 'global.php';

$url='tags_product';
$do=isset($_GET["do"])?clean($_GET["do"]):'view';	// 备用字段
$id=0; if (isset($_GET["id"])) $id = clean($_GET["id"]);
$page=1; if(isset($_GET["page"]))if(is_numeric($_GET["page"]))$page=$_GET["page"];
$tag_id = 0; if(isset($_GET['tag_id'])) $tag_id = clean($_GET['tag_id']);

$tags_info = $tags->get_row($tag_id);
$tag_list->rows = 16;
$where_tag = array();
$where_tag[] = array('name'=>'tag_id', 'val'=>$tag_id);
$order_by='p_id';
$pages = $tag_list->count_pages($where_tag);
$tag_list_info = $tag_list->get_page($page,$where_tag, $order_by, 'desc');
pre($tag_list_info);

$p_id_arr = array();
foreach($tag_list_info as $key => $val){
    $p_id_arr[] = $val['p_id'];
}

$url_all = curPageURL();

$product->rows=16;
$where=array();
$where[]=array('name'=>'id','val'=>$p_id_arr, 'opn'=>'in');
$order_by='id';
$pages=$product->count_pages($where);
$info=$product->get_page($page,$where,$order_by,'desc');

// new arrival
$tem = $product->get_rows_advanced(32,$where);
shuffle($tem);
$arr_new=array();
$k=0;
foreach($tem as $row) { $arr_new[]=$row; $k++; if($k==MAX_HOT_PRODUCT_SHOWN_SIDE) break; }

// 热销产品 hot_products
$tem = $product->get_rows(32,'is_enabled',1,'sold_quantity','desc');
shuffle($tem);
$arr_hot=array();
$k=0;
foreach($tem as $row) { $arr_hot[]=$row; $k++; if($k==MAX_HOT_PRODUCT_SHOWN_SIDE) break; }

//商品选项
$product_option_info = $product_option->get_rows(1024,'is_enabled', 1, 'seq_no');
pre($product_option_info);

//  历史记录 history
$history=get_history();
$has_history=count($history);
$where=array();
$where[]=array('name'=>'id','val'=>$p_id_arr, 'opn'=>'in');
$where[]=array('name'=>'id','val'=>$history,'opn'=>'in');
$tem = $product->get_rows_advanced(32,$where);
//shuffle($tem);
$arr_history=array();
$k=0;
foreach($tem as $row) { $arr_history[]=$row; $k++; if($k==MAX_RECENTLY_VIEWED_PRODUCT_SHOWN_SIDE) break; }

// SEO 设置 seo tags
$sort_name=$tags_info['name_'.$lang];
$title=WEB_HOT_ITEMS.' - '.$config['SITE_TITLE_'.LANG];
$kwd=$title;
$dpn=$kwd;

function curPageURL()
{
    $pageURL = 'http';

    if ($_SERVER["HTTPS"] == "on")
    {
        $pageURL .= "s";
    }
    $pageURL .= "://";

    if ($_SERVER["SERVER_PORT"] != "80")
    {
        $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
    }
    else
    {
        $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
    }
    return $pageURL;
}
// view 加载视图
require VIEW.$url.'.php';

// end of file
